home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
Libraries
/
SAT 2.3b4
/
Tutorial ƒ
/
Assignment5.p
< prev
next >
Wrap
Text File
|
1995-01-16
|
2KB
|
79 lines
program Assignment5;
uses
{$ifc UNDEFINED THINK_PASCAL}
Types, QuickDraw, Menus, Windows, TextEdit, Fonts, Dialogs, Memory, OSEvents, {}
{$endc}
SAT;
const
kSpeed = 5;
var
ignore: SpritePtr;
direction: Integer;
theSound: Handle;
procedure HandleSprite (me: SpritePtr);
begin
GetMouse(me^.position);
end; {HandleSprite}
procedure SetupSprite (me: SpritePtr);
begin
me^.task := @HandleSprite;
me^.face := SATGetFace(128);
SetRect(me^.hotRect, 0, 0, 32, 32);
end; {SetupSprite}
procedure SetupTarget (me: SpritePtr);
forward;
procedure HandleTarget (me: SpritePtr);
begin
me^.position.h := me^.position.h + direction;
if me^.position.h <= 0 then
direction := kSpeed;
if me^.position.h >= 200 then
direction := -kSpeed;
if me^.kind <> -1 then {Hit me!}
begin
me^.task := nil;
ignore := SATNewSprite(-1, 0, SATRand(gSAT.offSizeV), @SetupTarget);
{We could also re-use the old sprite for a new one, if we like.}
SATSoundPlay(theSound, 1, true);
end;
end; {HandleTarget}
procedure SetupTarget (me: SpritePtr);
begin
me^.task := @HandleTarget;
me^.face := SATGetFace(129);
SetRect(me^.hotRect, 0, 0, 32, 32);
direction := kSpeed;
end; {SetupTarget}
const
kTicksPerFrame = 2;
var
t: Longint;
begin
{$ifc UNDEFINED THINK_PASCAL}
SATInitToolbox;
{$endc}
SATInit(128, 129, 478, 302);
ignore := SATNewSprite(1, 200, 200, @SetupSprite);
ignore := SATNewSprite(-1, 0, SATRand(gSAT.offSizeV), @SetupTarget);
theSound := SATGetNamedSound('TestSound');
HideCursor;
while not Button do
begin
t := TickCount;
SATRun(true);
while TickCount < t + kTicksPerFrame do
;
end;
ShowCursor;
SATSoundShutup;
end.